package com.zking.frame.LYK;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import com.ibm.icu.text.SimpleDateFormat;
import com.zking.frame.TJ.mySpace;
import com.zking.frame.TL.Films;
import com.zking.frame.ZC.CinemaFrame;
import com.zking.utils.GetFilmAllData;
import com.zking.utils.UpdataTicketZ;



public class EnsureOrderJFrame extends JFrame implements MouseListener{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4046036008465008569L;
	private JPanel top_p;//导航栏面板
	private JButton payfor;//
	private JLabel logopic;
	private JLabel city;
	private JLabel homepage;
	private JLabel film;
	private JLabel cinema;
	private JLabel personData;
	private JLabel out;
	
	private JPanel center_top;//进度条面板
	private JLabel center_topl;
	private JLabel center_topc;
	private JLabel center_topr;
	private JLabel center_tops;
	
	private JPanel center_center;//中部倒计时面板
	private JLabel remind;
	private JLabel timeImg;
	private JLabel time;
	private static double nowTime;
	Container c = getContentPane();
	Map<String ,Object> map;
	public EnsureOrderJFrame(String name,String cinemaName1,String ting,String changci,int number,String seatNumber ) {
		map=GetFilmAllData.getFilmDataByName(name);
		lastTime lasttime=new lastTime();
		nowTime=System.currentTimeMillis();

		c.setLayout(null);//绝对布局，自己设定位置
		c.setBackground(Color.WHITE);
		

	
		 top_p=new JPanel();
		 top_p.setBounds(0,0,1482,90);
		 top_p.setLayout(null);
		 top_p.setBackground(Color.WHITE);
		 c.add(top_p);
		 //首页logo图片
		 ImageIcon logo=new ImageIcon("imges/logo.png");
		 
		 logopic=new JLabel(logo);
		 logopic.setBounds(60,0,logo.getIconWidth(),logo.getIconHeight());
		 top_p.add(logopic);
		 
		 //首页城市选择
		 city=new JLabel("湘潭") ;
		 city.setBounds(250, 10, 70, 40);
		 city.setFont(new Font("楷体", Font.CENTER_BASELINE, 30));
		 top_p.add(city);
		 
		 
		 //首页按钮
		 homepage=new JLabel("首页");
		 homepage.setBounds(360, 10, 70, 40);
		 homepage.setFont(new Font("楷体", Font.CENTER_BASELINE, 20));
		 homepage.addMouseListener(this);
	
		 top_p.add(homepage);
		 
		 //回到影视页面按钮
		 film=new JLabel("影片");
		 film.setBounds(480, 10, 70, 40);
		 film.setFont(new Font("楷体", Font.CENTER_BASELINE, 20));
		 top_p.add(film);
		 film.addMouseListener(this);
		 //回到影院的按钮
		 cinema=new JLabel("影院");
		 cinema.setBounds(590, 10, 70, 40);
		 cinema.setFont(new Font("楷体", Font.CENTER_BASELINE, 20));
		 cinema.addMouseListener(this);
		 top_p.add(cinema);
		 //个人中心
		 
		 personData=new JLabel("个人中心 |");
		 personData.setBounds(1230, 10, 120, 40);
		 personData.setFont(new Font("楷体", Font.CENTER_BASELINE, 20));
		 personData.addMouseListener(this);
		 top_p.add(personData);
		 
		 //退出
		 out=new JLabel("退出");
		 out.setBounds(1350, 10, 70, 40);
		 out.setFont(new Font("楷体", Font.CENTER_BASELINE, 20));
		 out.addMouseListener(this);
		 top_p.add(out);
		 
		 
		 center_top=new JPanel();
		 center_top.setLayout(new GridLayout(1,4,0,0));
		 center_top.setBounds(150, 100, 1300, 40);
		 center_top.setBackground(Color.WHITE);
		 c.add(center_top);
		 
		 center_topl=new JLabel("1.选择影片、场次");
		 center_topl.setForeground(Color.GREEN);
		 center_topl.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 15));
		 center_top.add(center_topl);
		 
		 center_topc=new JLabel("2.选座、填手机号");
		 center_topc.setForeground(Color.GREEN);
		 center_topc.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 15));
		 center_top.add(center_topc);
		 
		 
		 center_topr=new JLabel("3.确认订单、支付");
		 center_topr.setForeground(Color.GREEN);
		 center_topr.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 15));
		 center_top.add(center_topr);
		 
		 
		 center_tops=new JLabel("4.支付成功、影院取票观影");
		 center_tops.setForeground(Color.RED);
		 center_tops.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 15));
		 center_top.add(center_tops);
		 
		 center_center=new JPanel();
		 center_center.setBounds(150, 150, 1100, 100);
		 center_center.setBackground(Color.decode("#FFF3F3"));
		 center_center.setLayout(null);
		 c.add(center_center);
		 
		 remind=new JLabel("请确认您的订单信息，并请在15分钟内完成付款，如超时系统将自动释放已选座位");
		 remind.setBounds(40, 40, 800, 20);
		 remind.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 15));
		 remind.setForeground(Color.RED);
		 center_center.add(remind);
		 
		 ImageIcon icon1=new ImageIcon("imges/time.png");
		 timeImg =new JLabel(icon1);
		 timeImg.setBounds(840, 20, 60, 60);
		 center_center.add(timeImg);
		 
		 JLabel restRemind=new JLabel("剩余支付时间");
		 restRemind.setBounds(910, 20, 150, 20);
		 restRemind.setForeground(Color.GRAY);
		 center_center.add(restRemind);
		 
		 time=new JLabel("15:00");
		 time.setBounds(910, 45, 150, 40);
		 time.setFont(new Font("楷体", Font.CENTER_BASELINE, 30));
		 time.setForeground(Color.RED);
		 center_center.add(time);
		 lasttime.start();
		 JLabel orderId=new JLabel("订单号：7875993242424");
		 orderId.setBounds(150, 255, 300, 20);
		 orderId.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 10));
		 orderId.setForeground(Color.GRAY);
		 c.add(orderId);
		 
		 JLabel kefu=new JLabel("选座票由阿里影业凤凰云智提供，客服热线：0571——88157838");
		 kefu.setBounds(950, 255, 350, 20);
		 kefu.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 10));
		 kefu.setForeground(Color.GRAY);
		 c.add(kefu);
		 
		 JPanel  center_center_top=new JPanel();
		 center_center_top.setBounds(150, 280 ,1100, 30);
		 center_center_top.setBackground(Color.WHITE);
		 center_center_top.setLayout(null);
		 c.add(center_center_top);
		 
		 ImageIcon icon2=new ImageIcon("imges/ensurepic1.png");
		 JLabel filmL=new JLabel(icon2);
		 filmL.setBounds(50, 0,1000 ,30);
		 center_center_top.add(filmL);
		 
		 JPanel center_center_bottom=new JPanel();
		 center_center_bottom.setBounds(200, 320, 1000, 250);
		 center_center_bottom.setLayout(null);
		 center_center_bottom.setBackground(Color.WHITE);
		 c.add(center_center_bottom);
		 
		 ImageIcon icon3=new ImageIcon(map.get("图片")+"");
		 Image icon31=icon3.getImage().getScaledInstance(icon3.getIconWidth()-40, icon3.getIconHeight()-58, Image.SCALE_DEFAULT);
		 icon3.setImage(icon31);
		 JLabel filmImg=new JLabel(icon3);
		 filmImg.setBounds(0, 0,170, 250);
		 center_center_bottom.add(filmImg);
		 
		 JLabel filmName=new JLabel(name);
		 filmName.setBounds(160, 37,150, 30);
		 center_center_bottom.add(filmName);
		 filmName.setFont(new Font("楷体", Font.CENTER_BASELINE, 15));
		 
		 
		 JLabel filmvis=new JLabel("版本：国语2D");
		 filmvis.setBounds(160, 67, 150, 20);
		 filmvis.setFont(new Font("楷体", Font.CENTER_BASELINE, 12));
		 filmvis.setForeground(Color.GRAY);
		 center_center_bottom.add(filmvis);
		 
		 JLabel filmTime=new JLabel("片长："+map.get("片长")+"分钟");
		 filmTime.setBounds(160, 87, 150, 20);
		 filmTime.setFont(new Font("楷体", Font.CENTER_BASELINE, 12));
		 filmTime.setForeground(Color.GRAY);
		 center_center_bottom.add(filmTime);
		 
		 
		 JLabel ciname=new JLabel(cinemaName1);
		 ciname.setBounds(300,37, 200, 30);
		 ciname.setFont(new Font("楷体", Font.CENTER_BASELINE, 15));
		 center_center_bottom.add(ciname);
		 
		 JLabel cinameTing=new JLabel(ting);
		 cinameTing.setBounds(335, 87, 150, 30);
		 cinameTing.setFont(new Font("楷体", Font.CENTER_BASELINE, 15));
		 center_center_bottom.add(cinameTing);
		
		 JLabel showTime=new JLabel(changci);
		 showTime.setBounds(300, 137, 200, 30);
		 showTime.setFont(new Font("楷体", Font.CENTER_BASELINE, 15));
		 center_center_bottom.add(showTime);
		 
		 JLabel ticketNumber=new JLabel(number+"张");
		 ticketNumber.setBounds(552, 80, 50, 30);
		 ticketNumber.setFont(new Font("楷体", Font.CENTER_BASELINE, 15));
		 center_center_bottom.add(ticketNumber);
		 
		 JLabel seat=new JLabel(seatNumber);
		 seat.setBounds(540, 120, 80, 30);
		 seat.setFont(new Font("楷体", Font.CENTER_BASELINE, 12));
		 center_center_bottom.add(seat);
		 
		 JLabel price=new JLabel("￥28.90");
		 price.setBounds(650, 100, 80, 30);
		 price.setFont(new Font("楷体", Font.CENTER_BASELINE, 20));
		 price.setForeground(Color.RED);
		 center_center_bottom.add(price);
			GetUser uMsg=new GetUser();
		 JLabel phone=new JLabel(uMsg.getUserMsg().get(2)+"");
		 phone.setBounds(790, 37, 200, 30);
		 phone.setFont(new Font("楷体", Font.CENTER_BASELINE, 15));
		 phone.setBackground(Color.RED);
		 center_center_bottom.add(phone);
		 
		 JLabel tishi=new JLabel("1、短信可能手机软件拦截，请");
		 tishi.setBounds(770, 67, 200, 20);
		 tishi.setFont(new Font("楷体", Font.CENTER_BASELINE, 12));
		 tishi.setBackground(Color.RED);
		 center_center_bottom.add(tishi);
		 
		 JLabel tishi1=new JLabel("到该软件中查找短信");
		 tishi1.setBounds(770, 87, 160, 20);
		 tishi1.setFont(new Font("楷体", Font.CENTER_BASELINE, 12));
		 tishi1.setBackground(Color.RED);
		 center_center_bottom.add(tishi1);		 
		 
		 JLabel tishi2=new JLabel("2、若要修改手机号请重新下单");
		 tishi2.setBounds(770, 107, 180, 20);
		 tishi2.setFont(new Font("楷体", Font.CENTER_BASELINE, 12));
		 tishi2.setBackground(Color.RED);
		 center_center_bottom.add(tishi2);		 
		 
		 JPanel yitiaoxian=new JPanel();
		 yitiaoxian.setBounds(200, 580, 1000, 1);
		 yitiaoxian.setBackground(Color.GRAY);
		 c.add(yitiaoxian);
		 
		 
		 JLabel shifu=new JLabel("实付款：");
		 shifu.setBounds(1060, 600, 50, 20);
		 shifu.setForeground(Color.GRAY);
		 shifu.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 12));
		 c.add(shifu);
		 
		 JLabel money=new JLabel("￥28.90");
		 money.setBounds(1120, 595, 140, 30);
		 money.setForeground(Color.RED);
		 money.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 20));
		 c.add(money);
		 
		 payfor=new JButton("确认支付，立即下单");
		 payfor.setBounds(1000, 630, 200, 40);
		 payfor.setForeground(Color.WHITE);
		 payfor.setBackground(Color.RED);
		 payfor.addMouseListener(this);
		 c.add(payfor);
		 

		ImageIcon bottompic2=new ImageIcon("imges/bottompic2.png");
		JLabel bottomP2=new JLabel(bottompic2);
		bottomP2.setBounds(1, 770, 1482, 200);
		c.add(bottomP2);
		 
		 
		 
		 
		 
		 
		 
		 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);//点击关闭按钮退出
		setSize(1500, 1000);//尺寸
		setLocationRelativeTo(null);//居中
		setVisible(true);//可见		
		 
	}
	public List<Integer> getsid(){
		List list =new ArrayList<Integer>();
		String sql="select seat_id from seat";
		Connection conn= JDBC.getConn();
		PreparedStatement pst =null;
		ResultSet rs=null;
		try {
			pst=conn.prepareStatement(sql);
			rs=pst.executeQuery();
			while(rs.next()){
				int id=rs.getInt("seat_id");
				list.add(id);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		
		return list;
		
	}
	public List<Integer> getoid(){
		List list =new ArrayList<Integer>();
		String sql="select order_id from orderAll";
		Connection conn= JDBC.getConn();
		PreparedStatement pst =null;
		ResultSet rs=null;
		try {
			pst=conn.prepareStatement(sql);
			rs=pst.executeQuery();
			while(rs.next()){
				int id=rs.getInt("order_id");
				list.add(id);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return list;
		
	}
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Azhunuto-generated method stubu
		Object obj=e.getSource();
		if(obj==payfor){
			List list=getsid();
			List list2=getoid();
			dispose();
			UpdataTicketZ.updataTs((int)list.get(list.size()-1));
			UpdataTicketZ.updataTo((int)list2.get(list2.size()-1));
			JOptionPane.showMessageDialog(c, "购票成功，祝你观影愉快");
			new mySpace();
		}
		else if(obj==personData) {
			dispose();
			new mySpace();
		}
		else if(obj==out) {
			dispose();
		}
		else if(obj==homepage) {
			dispose();
			new HomepageJframe();
		}
		else if(obj==film) {
		
			dispose();
			new Films();
			
		}
		else if(obj==cinema){
			dispose();
			new CinemaFrame();
		}
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

class lastTime extends Thread {
	double last;
	int min=14;
	int mia=59;
	@Override
	public void run() {
		
		while (last<=899990){
			 last=System.currentTimeMillis()-nowTime;
			try {
				
					
			
				sleep(1000);
				time.setText(min+":"+mia);
				
				mia--;
				if(mia==0){
					sleep(1000);
					mia=59;
					min--;
				}
				if(min==0){
					JOptionPane.showMessageDialog(c, "已超时，购票失败");
				}
				
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		}
		stop();
	}
}
}  
